package CreationalPatterns.Builder.builder;

import CreationalPatterns.Builder.components.Engine;
import CreationalPatterns.Builder.components.TripComputer;
import CreationalPatterns.Builder.product.*;

public class SportsCarBuilder implements CarBuilder {
    // 设置默认值的好处是可以把Director的职责放到Builder中，好处是减少了复杂性以及可以通过一个『配置变量』控制Builder但不利于扩展
    private SportsCar car;
    private Integer seatNumber = 6;
    private Engine engine = Engine.SPORT_CAR_ENGINE;
    private TripComputer tripComputer = TripComputer.SPORT_CAR_TRIP_COMPUTER;
    private Integer spareTireNumber = 1; // 默认备用轮胎为1

    @Override
    public void reset() {
        this.car = new SportsCar();
    }

    @Override
    public void setSeats(Integer number) {
        this.seatNumber = number;
    }

    @Override
    public void setEngine(Engine engine) {
        this.engine = engine;

    }

    @Override
    public void setTripComputer(TripComputer tripComputer) {
        this.tripComputer = tripComputer;
    }

    @Override
    public Boolean isHasSpareTire() {
        return true;
    }

    @Override
    public void setSpareTire(Integer number) {
        this.spareTireNumber = number;
    }

    @Override
    public Car build() {
        car = new SportsCar();
        car.setSeatNumber(seatNumber);
        car.setEngine(engine);
        car.setTripComputer(tripComputer);
        if (this.isHasSpareTire()) {
            car.setSpareTireNumber(this.spareTireNumber);
        }
        return car;
    }
}
